﻿using MyRoguelike.Screens.Manager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyRoguelike.Game;
using MyRoguelike.Tools;
using MyRoguelike.GUI;

namespace MyRoguelike.Screens.MyScreens
{
    class GameScreen : Screen
    {
        private Level _level;

        private GUIInventory _guiInventory;
        private GUIHealthBar _guiHealthBar;

        public GameScreen()
            : base()
        {
        }

        public override void Initialize()
        {
            _level = new Level();

            _level.Initialize();
            _level.Generation(100, 100);

            // Init GUI
            _guiInventory = new GUIInventory(_level.Player);

            _guiHealthBar = new GUIHealthBar(
                ResourceManager.Textures["GUIHealthBarBack"],
                ResourceManager.Textures["GUIHealthBarForeg"],
                _level.Player);
            _guiHealthBar.Position = new Vector2(20, 20);
        }

        public override void LoadContent()
        {
            // Load textures
            ResourceManager.AddTexture("Floor", "Gfx/floor");
            ResourceManager.AddTexture("Wall", "Gfx/wall");

            ResourceManager.AddTexture("Player", "Gfx/player");
            ResourceManager.AddTexture("Skeleton", "Gfx/skeleton");

            ResourceManager.AddTexture("GUIHealthBarBack", "Gfx/gui_health_bar_back");
            ResourceManager.AddTexture("GUIHealthBarForeg", "Gfx/gui_health_bar_foreg");

            // Load fonts
            ResourceManager.AddFont("Inventory", "Fonts/inventory");
        }

        public override void Update(GameTime gameTime)
        {
            _level.Update(gameTime);

            _guiInventory.Update(gameTime);

            // Update input
            InputManager.Update();
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            _level.Draw(spriteBatch);

            // Draw GUI
            _guiHealthBar.Draw(spriteBatch);
            _guiInventory.Draw(spriteBatch);

            spriteBatch.End();
        }

        public override void UnloadContent()
        {
            ResourceManager.DelTexture("Floor");
            ResourceManager.DelTexture("Wall");

            ResourceManager.DelTexture("Player");
        }

        public override void Shutdown()
        {
        }
    }
}
